2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIContentController.h"
18 #import "CBOldPrefsImporterAppController.h"
19 #import <AIUtilities/AIUtilities.h>
22 #define ADIUM_1X_LOGS_PATH @"~/Library/Application Support/Adium/Users"
24 //Stupid Proteus status codes..
25 #define PROTEUS_AWAY_STATUS 7
26 #define PROTEUS_3_STATUS [[[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"Instant Messaging"] stringByAppendingPathComponent:@"Profile"] stringByAppendingPathComponent:@"Status.plist"]
27 #define PROTEUS_4_STATUS [[[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"Proteus"] stringByAppendingPathComponent:@"Profile"] stringByAppendingPathComponent:@"Status.plist"]
31 @interface CBOldPrefsImporterAppController(PRIVATE)
32 - (void)importAliases;
33 - (void)importContacts;
36 @implementation CBOldPrefsImporterAppController
40 iconDict = [[[NSMutableDictionary alloc] init] retain];
41 [contentController initController];
42 [tabView_ClientTabs selectTabViewItemAtIndex:0];
43 [popUpButton_account removeItemAtIndex:0];
44 [popUpButton_user removeItemAtIndex:0];
45 [progressIndicator setIndeterminate:NO];
46 [progressIndicator setUsesThreadedAnimation:YES];
48 [spinner_ClientProgress setUsesThreadedAnimation:YES];
49 [spinner_ClientProgress setHidden:NO];
50 [spinner_ClientProgress startAnimation:nil];
51 [spinner_ClientProgress display];
53 [popUpButton_Clients setAction:@selector(changeClientSelection:)];
54 [popUpButton_Clients setAutoenablesItems:NO];
60 NSString *dirPath = [@"~/Library/Application Support/Adium/Users" stringByExpandingTildeInPath];
61 NSDirectoryEnumerator *enumer = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
63 while((file = [enumer nextObject]))
65 [enumer skipDescendents];
66 if([[[enumer fileAttributes] objectForKey:@"NSFileType"] isEqual:@"NSFileTypeDirectory"])
67 [popUpButton_account addItemWithTitle:file];
70 dirPath = [@"~/Library/Application Support/Adium 2.0/Users" stringByExpandingTildeInPath];
71 enumer = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
72 [popUpButton_user removeAllItems];
74 while((file = [enumer nextObject]))
76 [enumer skipDescendents];
77 if([[[enumer fileAttributes] objectForKey:@"NSFileType"] isEqual:@"NSFileTypeDirectory"])
79 if (![file isEqualToString:@".DS_Store"])
81 [popUpButton_user addItemWithTitle:file];
86 [window_main makeKeyAndOrderFront:nil];
89 if([popUpButton_account numberOfItems] == 0){
90 [popUpButton_account setEnabled:NO];
91 [button_Adium_Logs setEnabled:NO];
92 [button_Adium_Aliases setEnabled:NO];
93 [button_Adium_Contacts setEnabled:NO];
94 [popUpButton_account addItemWithTitle:@"No Adium 1.x Prefs found."];
95 [popUpButton_account selectItemWithTitle:@"No Adium 1.x Prefs found."];
96 //NSBeginAlertSheet(@"Nothing to import", @"Quit", nil, nil, window_main, NSApp, @selector(terminate:), nil, nil, @"I cannot find any Adium 1.x preferences to import.");
102 if([popUpButton_user numberOfItems] == 0){
103 NSBeginAlertSheet(@"Run Adium 2 first", @"Quit", nil, nil, window_main, NSApp, @selector(terminate:), nil, nil, @"You must run Adium 2 before any settings can be imported");
107 //Multiple Adium 2.0 users
108 //if([popUpButton_user numberOfItems] > 1)
110 // [NSApp beginSheet:theSheet
111 // modalForWindow:window_main
112 // modalDelegate:self
113 // didEndSelector:nil
117 //Here comes the other client stuff yeah yeah yeah!!
121 NSString *settingsPath;
122 NSFileManager *manager = [NSFileManager defaultManager];
123 [popUpButton_Clients removeItemAtIndex:0];
125 path = [[NSString alloc]init];
126 path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"iChat"];
127 [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"iChat"];
128 settingsPath = [[NSString stringWithString:@"~/Library/Preferences/com.apple.iChat.plist"] stringByExpandingTildeInPath];
130 [popUpButton_Clients addItemWithTitle:@"iChat"];
132 item = (NSMenuItem *)[popUpButton_Clients lastItem];
133 icon = [iconDict objectForKey:[item title]];
134 [icon setSize:NSMakeSize(16,16)];
135 [item setImage:icon];
136 if([manager fileExistsAtPath:settingsPath]){
137 [item setEnabled:YES];
139 [item setEnabled:NO];
142 path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"Proteus"];
143 [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"Proteus"];
144 settingsPath = [@"~/Library/Application Support/Proteus/" stringByExpandingTildeInPath];
145 [popUpButton_Clients addItemWithTitle:@"Proteus"];
146 item = (NSMenuItem *)[popUpButton_Clients lastItem];
147 icon = [iconDict objectForKey:[item title]];
148 [icon setSize:NSMakeSize(16,16)];
149 [item setImage:icon];
150 if([manager fileExistsAtPath:settingsPath]){
151 [item setEnabled:YES];
153 [item setEnabled:NO];
156 path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"Fire"];
157 [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"Fire"];
158 settingsPath = [@"~/Library/Application Support/Fire/" stringByExpandingTildeInPath];
159 [popUpButton_Clients addItemWithTitle:@"Fire"];
160 item = (NSMenuItem *)[popUpButton_Clients lastItem];
161 if ([[NSFileManager defaultManager] fileExistsAtPath:path]){
162 icon = [iconDict objectForKey:[item title]];
164 icon = [NSImage imageNamed:@"ErrorAlert"];
166 [icon setSize:NSMakeSize(16,16)];
168 [item setImage:icon];
169 if([manager fileExistsAtPath:settingsPath]){
170 [item setEnabled:YES];
172 [item setEnabled:NO];
175 [spinner_ClientProgress stopAnimation:nil];
176 [spinner_ClientProgress setHidden:YES];
182 [contentController closeController];
185 - (NSMutableArray *)_loadAwaysFromArray:(NSArray *)array
187 NSEnumerator *enumerator;
189 NSMutableArray *mutableArray = [NSMutableArray array];
191 enumerator = [array objectEnumerator];
192 while((dict = [enumerator nextObject])){
193 NSString *type = [dict objectForKey:@"Type"];
195 if([type isEqualToString:@"Group"]){
196 [mutableArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
198 [self _loadAwaysFromArray:[dict objectForKey:@"Contents"]], @"Contents",
199 [dict objectForKey:@"Name"], @"Name",
202 }else if([type isEqualToString:@"Away"]){
203 NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
204 NSString *title = [dict objectForKey:@"Title"];
205 NSData *autoresponse = [dict objectForKey:@"Autoresponse"];
207 [newDict setObject:@"Away" forKey:@"Type"];
208 [newDict setObject:[NSAttributedString stringWithData:[dict objectForKey:@"Message"]] forKey:@"Message"];
210 if(title && [title length]){
211 [newDict setObject:title forKey:@"Title"];
215 [newDict setObject:[NSAttributedString stringWithData:autoresponse] forKey:@"Autoresponse"];
218 [mutableArray addObject:newDict];
221 return(mutableArray);
224 //Recursively build a savable away message array (replacing NSAttributedString with NSData)
225 - (NSArray *)_saveArrayFromArray:(NSArray *)array
227 NSEnumerator *enumerator;
229 NSMutableArray *saveArray = [NSMutableArray array];
231 enumerator = [array objectEnumerator];
232 while((dict = [enumerator nextObject])){
233 NSString *type = [dict objectForKey:@"Type"];
235 if([type isEqualToString:@"Group"]){
236 [saveArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:
238 [self _saveArrayFromArray:[dict objectForKey:@"Contents"]], @"Contents",
239 [dict objectForKey:@"Name"], @"Name",
242 }else if([type isEqualToString:@"Away"]){
243 NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
244 NSString *title = [dict objectForKey:@"Title"];
245 NSData *autoresponse = [[dict objectForKey:@"Autoresponse"] dataRepresentation];
247 [newDict setObject:@"Away" forKey:@"Type"];
248 [newDict setObject:[[dict objectForKey:@"Message"] dataRepresentation] forKey:@"Message"];
250 if(title && [title length]){
251 [newDict setObject:title forKey:@"Title"];
255 [newDict setObject:autoresponse forKey:@"Autoresponse"];
258 [saveArray addObject:newDict];
265 - (BOOL)ensureAdiumIsClosed
267 NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
268 NSEnumerator*enumerator;
269 NSDictionary*appDict;
271 enumerator = [apps objectEnumerator];
272 while((appDict = [enumerator nextObject])){
273 if([[appDict objectForKey:@"NSApplicationName"] rangeOfString:@"Adium"].location != NSNotFound &&
274 [[appDict objectForKey:@"NSApplicationName"] rangeOfString:@"Importer"].location == NSNotFound){
276 NSBeginAlertSheet(@"Adium is running", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Please close all copies of Adium before importing.");
287 - (IBAction)sheetButton:(id)sender
289 [[sender window] orderOut:self];
290 [NSApp endSheet:[sender window] returnCode:YES];
294 - (IBAction)importContacts:(id)sender
296 [NSApp beginSheet:importListSheet
297 modalForWindow:window_main
304 - (IBAction)importLogs:(id)sender
306 if([self ensureAdiumIsClosed]){
308 NSString *importingFromAccount = [popUpButton_account titleOfSelectedItem];
309 NSString *importingForAccount = [popUpButton_user titleOfSelectedItem];
310 NSString *newLogFolder;
311 NSString *oldUserFolder;
312 NSString *oldLogFolder;
313 NSEnumerator *logEnumerator;
316 NSFileManager *defaultFileManager = [NSFileManager defaultManager];
319 [progressIndicator setIndeterminate:YES];
320 [progressIndicator startAnimation:nil];
322 //We scan through the log folder, and copy each log as we come across it
323 oldUserFolder = [ADIUM_1X_LOGS_PATH stringByExpandingTildeInPath];
324 newLogFolder = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Logs", importingForAccount] stringByExpandingTildeInPath];
328 //For every contact they messaged
329 oldLogFolder = [[oldUserFolder stringByAppendingPathComponent:importingFromAccount] stringByAppendingPathComponent:@"Logs"];
330 logEnumerator = [[defaultFileManager directoryContentsAtPath:oldLogFolder] objectEnumerator];
331 while((subFolder = [logEnumerator nextObject])){
332 NSString *subFolderPath;
333 NSEnumerator *fileEnumerator;
336 //For every log file they have
337 subFolderPath = [oldLogFolder stringByAppendingPathComponent:subFolder];
338 fileEnumerator = [[defaultFileManager directoryContentsAtPath:subFolderPath] objectEnumerator];
339 while((fileName = [fileEnumerator nextObject])){
340 NSString *newPath = [NSString stringWithFormat:@"%@/AIM.%@/%@", newLogFolder, importingFromAccount, subFolder];
343 [currentTask setStringValue:[NSString stringWithFormat:@"Copying %@", fileName]];
344 [currentTask display];
345 [progressIndicator animate:nil];
346 [progressIndicator display];
349 [defaultFileManager createDirectoriesForPath:newPath];
350 [defaultFileManager copyPath:[subFolderPath stringByAppendingPathComponent:fileName]
351 toPath:[newPath stringByAppendingPathComponent:fileName]
357 [progressIndicator stopAnimation:nil];
358 [progressIndicator setNeedsDisplay:YES];
359 [currentTask setStringValue:@"Log import complete."];
362 - (IBAction)importAliases:(id)sender
364 NSString *importingFromAccount = [popUpButton_account titleOfSelectedItem];
365 NSString *importingForAccount = [popUpButton_user titleOfSelectedItem];
367 if([self ensureAdiumIsClosed]){
369 [progressIndicator setIndeterminate:YES];
370 [progressIndicator startAnimation:nil];
372 //Open the Adium 1.x buddy list
373 NSString *path = nil;
374 NSString *listAccount = importingFromAccount;
375 NSDictionary *buddyList = nil;
376 // Load the appropriate buddy list
377 while (buddyList == nil && listAccount != nil) {
378 path = [[NSString stringWithFormat:@"~/Library/Application Support/Adium/Users/%@/BuddyList.plist", listAccount] stringByExpandingTildeInPath];
379 buddyList = [NSDictionary dictionaryWithContentsOfFile:path];
381 // If this user shares another user's buddy list, get that one.
382 if ([buddyList objectForKey:@"shareBuddyListWith"] != nil) {
384 listAccount = [buddyList objectForKey:@"shareBuddyListWith"];
386 // Bust endless loops
387 if ([listAccount isEqualToString:importingFromAccount]) {
389 NSBeginAlertSheet(@"Shared buddy list problem", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"An unforseen problem with buddy lists endlessly sharing each other has occurred.Ê If you do not know the cause, please contact an Adium developer.");
390 [currentTask setStringValue:@"Alias import failed."];
397 if (listAccount && buddyList){
398 //Scan through all the buddies and groups
399 int numGroups = [[buddyList objectForKey:@"numGroups"] intValue];
401 NSFileManager *defaultFileManager = [NSFileManager defaultManager];
403 for(i = 0; i < numGroups; i++){
404 NSDictionary *group = [buddyList objectForKey:[NSString stringWithFormat:@"group %d", i]];
405 int numContacts = [[group objectForKey:@"numberOfBuddies"] intValue];
407 for(j = 0; j < numContacts; j++){
409 NSString *alias = [group objectForKey:[NSString stringWithFormat:@"alias %d", j]];
410 if(alias && ![alias isEqualToString:@""]){
411 NSString *screenname;
413 NSMutableDictionary *prefDict;
415 screenname = [[[group objectForKey:[NSString stringWithFormat:@"buddy %d", j]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] lowercaseString];
417 //Update our progress display
418 [currentTask setStringValue:[NSString stringWithFormat:@"Importing alias for %@", screenname]];
419 [currentTask display];
420 [progressIndicator animate:nil];
421 [progressIndicator display];
423 //Open the 2.0 object specific preference file for this contact
424 prefPath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/ByObject/AIM.%@.plist", importingForAccount, screenname] stringByExpandingTildeInPath];
425 prefDict = [NSMutableDictionary dictionaryWithContentsOfFile:prefPath];
426 if(!prefDict) prefDict = [NSMutableDictionary dictionary];
428 //Add the alias key to it
429 [prefDict setObject:alias forKey:@"Alias"];
432 [defaultFileManager createDirectoriesForPath:[prefPath stringByDeletingLastPathComponent]];
434 [prefDict writeToFile:prefPath atomically:YES];
440 [currentTask setStringValue:@"Alias import complete."];
442 [progressIndicator stopAnimation:nil];
443 [progressIndicator setNeedsDisplay:YES];
447 /*- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)code contextInfo:(void *)info
451 [progressIndicator setIndeterminate:YES];
452 [progressIndicator startAnimation:self];
453 [button_import setEnabled:NO];
454 [popUpButton_account setEnabled:NO];
456 if([checkBox_contacts state] == NSOnState
457 && [popUpButton_account selectedItem])
459 [self importContacts];
461 if([checkBox_aliases state] == NSOnState
462 && [popUpButton_account selectedItem])
464 [self importAliases];
467 [currentTask setStringValue:@""];
468 [progressIndicator stopAnimation:nil];
469 [progressIndicator setIndeterminate:NO];
470 [button_import setEnabled:YES];
471 [popUpButton_account setEnabled:YES];
475 /*- (void)importContacts
480 /*- (void)importAliases;
486 #pragma mark Other Client Shtuff
488 - (IBAction)importAwayMessages:(id)sender
490 if([self ensureAdiumIsClosed]){
491 NSString *whichClient;
492 whichClient = [popUpButton_Clients titleOfSelectedItem];
494 if(whichClient == @"iChat"){
495 [self importiChatAways];
497 else if(whichClient == @"Proteus"){
498 [self importProteusAways];
500 else if(whichClient == @"Fire"){
501 [self importFireAways];
506 - (void)importiChatAways
508 [spinner_importProgress setHidden:NO];
509 [spinner_importProgress startAnimation:nil];
510 [spinner_importProgress display];
511 NSAttributedString *newiChatAwayString;
512 NSMutableDictionary *newAdiumAwayDict;
513 NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
515 // Create array of iChat away messages
516 NSString *iChatPath = [NSString stringWithString:[@"~/Library/Preferences/com.apple.iChat.plist" stringByExpandingTildeInPath]];
517 NSDictionary *iChatDict = [NSDictionary dictionaryWithContentsOfFile:iChatPath];
518 NSArray *iChatMessageArray = [iChatDict objectForKey:@"CustomAwayMessages"];
520 // Create an array of Adium's away messages
521 NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
522 NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
524 NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
525 NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
526 // Or, create a blank list if we've never saved one before
527 if (AdiumMessageArray == nil)
528 AdiumMessageArray = [NSMutableArray array];
531 // Loop through each iChat away message
532 NSEnumerator *iChatEnumerator = [iChatMessageArray objectEnumerator];
533 NSEnumerator *AdiumEnumerator = NULL;
534 NSDictionary *AdiumMessage;
535 NSString *iChatMsgTitle, *iChatMsgContent;
536 NSString *AdiumMsgTitle, *AdiumMsgContent;
537 BOOL messageAlreadyExists;
539 while((iChatMsgContent = [iChatEnumerator nextObject]))
542 // Create a title for the message by truncating it
543 iChatMsgTitle = [iChatMsgContent stringWithEllipsisByTruncatingToLength:25];
545 // Loop through each Adium away message and compare it to the current iChat message
546 AdiumEnumerator = [AdiumMessageArray objectEnumerator];
547 messageAlreadyExists = NO;
549 while((AdiumMessage = [AdiumEnumerator nextObject]))
551 AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
552 AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
554 // If either the title or the content matches, we assume it's already been imported...
555 if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:iChatMsgTitle] || [AdiumMsgContent isEqual:iChatMsgContent])) {
556 messageAlreadyExists = YES;
561 // If the message isn't already in Adium's list, add it
562 if (!messageAlreadyExists) {
564 // Casting like a drunk fisherman...
565 newiChatAwayString = [[[NSAttributedString alloc] initWithString:iChatMsgContent
566 attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
568 // Add the away message to the array... hallelujah!
570 newAdiumAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newiChatAwayString,@"Message", iChatMsgTitle, @"Title", nil];
573 [AdiumMessageArray addObject:newAdiumAwayDict];
576 NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
577 [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
578 NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
579 [spinner_importProgress stopAnimation:nil];
580 [spinner_importProgress setHidden:YES];
582 if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
584 NSBeginAlertSheet(@"iChat messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your iChat away messages have been imported and are now available in Adium.");
588 NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
594 - (void)importProteusAways
596 [spinner_importProgress setHidden:NO];
597 [spinner_importProgress startAnimation:nil];
598 [spinner_importProgress display];
599 NSAttributedString *newAwayString;
600 NSMutableDictionary *newAwayDict;
601 NSFileManager *manager;
602 NSString *proteusPath;
603 NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
605 //Create an array of Proteus Away Messages
606 manager = [[NSFileManager alloc] init];
607 if([manager fileExistsAtPath:PROTEUS_3_STATUS])
608 proteusPath = PROTEUS_3_STATUS;
610 proteusPath = PROTEUS_4_STATUS;
612 NSDictionary *proteusDict = [NSDictionary dictionaryWithContentsOfFile:proteusPath];
613 NSArray *proteusMessageArray = [proteusDict objectForKey:@"Custom Status Modes"];
616 // Create an array of Adium's away messages
617 NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
618 NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
619 NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
620 NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
621 // Or, create a blank list if we've never saved one before
622 if (AdiumMessageArray == nil)
623 AdiumMessageArray = [NSMutableArray array];
625 // Loop through each Proteus away message
626 NSEnumerator *AdiumEnumerator = NULL;
627 NSDictionary *AdiumMessage;
628 NSDictionary *proteusMessage/*, *proteusCurrentMessage*/;
629 NSString *AdiumMsgTitle, *AdiumMsgContent;
630 NSString *proteusMsgTitle, *proteusMsgContent;
631 BOOL messageAlreadyExists;
632 // BOOL importAllStatus;
638 //Get us an array of all the keys in the dictionary
640 NSEnumerator *proteusEnumerator = [proteusMessageArray objectEnumerator];
641 while((proteusMessage = [proteusEnumerator nextObject]))
644 proteusMsgTitle = [proteusMessage objectForKey:@"Name"];
645 proteusMsgContent = [proteusMessage objectForKey:@"Message"];
646 NSLog(proteusMsgTitle);
647 NSLog(proteusMsgContent);
649 //If we want to import ALL of the messages and not just ones for the away status...
650 if([button_importAllProteusAways state] == NSOnState){
653 // Loop through each Adium away message and compare it to the current proteus message
654 AdiumEnumerator = [AdiumMessageArray objectEnumerator];
655 messageAlreadyExists = NO;
657 while((AdiumMessage = [AdiumEnumerator nextObject]))
659 // If either the title or the content matches, we assume it's already been imported...
660 AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
661 AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
663 if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:proteusMsgTitle] || [AdiumMsgContent isEqual:proteusMsgContent])) {
664 messageAlreadyExists = YES;
668 // If the message isn't already in Adium's list, add it
669 if (!messageAlreadyExists)
672 // Casting like a drunk fisherman...
673 newAwayString = [[[NSAttributedString alloc] initWithString:proteusMsgContent
674 attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
676 // Add the away message to the array... hallelujah!
678 newAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newAwayString,@"Message", proteusMsgTitle, @"Title", nil];
681 [AdiumMessageArray addObject:newAwayDict];
687 NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
688 [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
689 NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
690 [spinner_importProgress stopAnimation:nil];
691 [spinner_importProgress setHidden:YES];
693 if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
695 NSBeginAlertSheet(@"Proteus messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your Proteus away messages have been imported and are now available in Adium.");
699 NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
706 - (void)importFireAways
708 [spinner_importProgress setHidden:NO];
709 [spinner_importProgress startAnimation:nil];
710 [spinner_importProgress display];
711 NSAttributedString *newAwayString;
712 NSMutableDictionary *newAwayDict;
713 NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
715 //Create an array of Fire Away Messages
716 NSString *firePath = [NSString stringWithString:[@"~/Library/Application Support/Fire/FireConfiguration.plist" stringByExpandingTildeInPath]];
718 NSDictionary *fireDict = [NSDictionary dictionaryWithContentsOfFile:firePath];
719 NSDictionary *fireMessageDict = [fireDict objectForKey:@"awayMessages"];
722 // Create an array of Adium's away messages
723 NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
724 NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
725 NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
726 NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
727 // Or, create a blank list if we've never saved one before
728 if (AdiumMessageArray == nil)
729 AdiumMessageArray = [NSMutableArray array];
732 // Loop through each Fire away message
733 NSEnumerator *AdiumEnumerator = NULL;
734 NSDictionary *AdiumMessage;
735 NSDictionary *fireMessage;
736 NSString *AdiumMsgTitle, *AdiumMsgContent;
737 NSString *fireMsgTitle, *fireMsgContent;
738 BOOL messageAlreadyExists;
740 //Get us an array of all the keys in the dictionary
741 NSArray *fireKeyArray = [[[NSArray alloc] initWithArray:[fireMessageDict allKeys]] autorelease];
743 NSEnumerator *fireEnumerator = [fireKeyArray objectEnumerator];
744 while((fireMsgTitle = [fireEnumerator nextObject]))
746 fireMessage = [fireMessageDict objectForKey:fireMsgTitle];
748 fireMsgContent = [fireMessage objectForKey:@"message"];
750 NSLog(fireMsgContent);
752 // Loop through each Adium away message and compare it to the current Fire message
753 AdiumEnumerator = [AdiumMessageArray objectEnumerator];
754 messageAlreadyExists = NO;
756 while((AdiumMessage = [AdiumEnumerator nextObject]))
758 // If either the title or the content matches, we assume it's already been imported...
759 AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
760 AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
762 if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:fireMsgTitle] || [AdiumMsgContent isEqual:fireMsgContent])) {
763 messageAlreadyExists = YES;
769 // If the message isn't already in Adium's list, add it
770 if (!messageAlreadyExists)
773 // Casting like a drunk fisherman...
774 newAwayString = [[[NSAttributedString alloc] initWithString:fireMsgContent
775 attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
777 // Add the away message to the array... hallelujah!
779 newAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newAwayString,@"Message", fireMsgTitle, @"Title", nil];
782 [AdiumMessageArray addObject:newAwayDict];
786 NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
787 [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
788 NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
789 [spinner_importProgress stopAnimation:nil];
790 [spinner_importProgress setHidden:YES];
792 if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
794 NSBeginAlertSheet(@"Fire messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your Fire away messages have been imported and are now available in Adium.");
798 NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
807 #pragma mark Application Delegate Methods & Other Ugly Stuff(tm)
809 - (IBAction)changeClientSelection:(id)sender
811 [tabView_ClientTabs selectTabViewItemWithIdentifier:[popUpButton_Clients titleOfSelectedItem]];;
814 - (AIContentController *)contentController
816 return(contentController);
819 - (void)applicationDidFinishLaunching: (NSNotification *)aNotification
824 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication